import 'dart:io';

import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:finance_app/src/utils/date_time_utils.dart';
import 'package:path/path.dart' as path;

class HttpAccountService {
  /// 账号列表
  static Future<Response> accountList() {
    return BaseConfig.httpBase.get('/api/accounts', null);
  }

  static Future<Response> accountCreate(String accountNumber, String bankName,
      String currencyCode, num balance, DateTime dateTime) {
    return BaseConfig.httpBase.postJson('/api/accounts', {
      "account_number": accountNumber,
      "bank_name": bankName,
      "currency_code": currencyCode,
      "balance": balance,
      'as_at': DateTimeUtils.formatDateTime(dateTime, 'yyyy-MM-dd'),
    });
  }

  static Future<Response> accountUpdate(int accountId, String accountNumber,
      String bankName, String currencyCode, num balance, DateTime dateTime) {
    return BaseConfig.httpBase.putJson('/api/accounts/$accountId', {
      "account_number": accountNumber,
      "bank_name": bankName,
      "currency_code": currencyCode,
      "balance": balance,
      'as_at': DateTimeUtils.formatDateTime(dateTime, 'yyyy-MM-dd'),
    });
  }

  static Future<Response> showAccount(int accountId) {
    return BaseConfig.httpBase.get('/api/accounts/$accountId', {});
  }

  static Future<Response> deleteAccount(int accountId) {
    return BaseConfig.httpBase.deleteJson('/api/accounts/$accountId', {});
  }

  static Future<Response> getBankReconciliations(int accountId) {
    return BaseConfig.httpBase.get('/api/bank_reconciliations', {
      'account_id': accountId,
    });
  }

  static Future<Response> createBankReconciliations({
    int accountId,
    String start_date,
    String end_date,
    num statement_balance,
    List attachment_ids,
  }) async {
    return BaseConfig.httpBase.postJson('/api/bank_reconciliations', {
      'account_id': accountId,
      'start_date': start_date,
      'end_date': end_date,
      'statement_balance': statement_balance,
      'attachment_ids': attachment_ids ?? [],
    });
  }
}
